package com.it.sun.yuebike.framework.config;

import cn.hutool.core.lang.Assert;
import com.it.sun.yuebike.framework.util.MinioUtils;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @ClassName com.it.sun.yuebike.framework.config.MinioConfig
 * @Author sunmannian
 * @Date 2021/6/1 17:33
 * @Version V1.0
 * Description  <请输入一句话描述该类功能>
 * Copyright (C) 北京中电兴发科技有限公司  since 2021/6/1
 */
@Configuration
public class MinioConfig implements InitializingBean {

    @Autowired
    private MinioProperties minioProperties;

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.notNull(minioProperties);
        MinioUtils.properties = minioProperties;
        MinioUtils.client = new MinioClient(minioProperties.endpoint, minioProperties.port, minioProperties.accessKey, minioProperties.secretKey);
    }


    @ConfigurationProperties(prefix = "minio")
    @Component
    @Data
    public static class MinioProperties {

        private String endpoint;

        private String accessKey;

        private String secretKey;

        private String downloadUrl;

        private int port;

    }
}



